(function(jwplayer){
    var template = function(player, config, div) {
    	var count = 0;
    	var player_width, player_height;
    	function show_ad() {
	        div.style.display = '';
	        var left = (player_width/2 - config.width/2)+'px';
	        var top = ((player_height - config.height-30)/2)+'px';
	        div.innerHTML = "<div style='width: 307px; height: 283px; \
	        					border: 0px; overflow: hidden; margin-left: 160px; margin-top: 40px'> \
	        			<iframe style='width: 308px; height: 258px; border: 0px; overflow: hidden; volume: silent;' \
	        					src='"+config.url+"' scrolling='no'></iframe>\
	                            <a href='#' style='display: block; width "+(config.width-10)+"px; height: 20px; margin: 0 auto; \
	                                        line-height: 20px; background: white; color: black; \
	                                        margin-top: 4px; text-align: center; border-radius: 3px; text-decoration: none\
	                                        ' onClick='this.parentNode.parentNode.style.display=\"none\";this.parentNode.parentNode.innerHTML=\"\"; return false'>Close Ad</a></div>";
	                                        
	    }

        function setup(evt) {
        	player_width = player.getWidth();
        	player_height = player.getHeight();
            div.style.color = '#F00';
	        show_ad();
	        div.style.width = player_width+'px';
	        div.style.height = (player_height-30)+'px';
        }
        player.onReady(setup);
	    player.onPlay(function(evt) {
        	count++;
	    });
	    player.onPause(function(evt) {
        	if ( count )
	        	show_ad();
	    });
	    player.onComplete(function(evt) {
        	if ( count )
	    		show_ad();
	    });
	    function close_ad() {
	        div.innerHTML = '';
	    }
        this.resize = function(width, height) {
        	div.style.width = player_width+'px';
	        div.style.height = (player_height-30)+'px';
	        div.style.position = 'absolute';
	        div.style.left = (width/2 - config.width/2)+'px';
	        div.style.top = ((height-config.height-30)/2)+'px';
	    };
    };
    jwplayer().registerPlugin('ads.v5', template);
})(jwplayer);